wayland: unlink shm file earlier in create function
authorRay Strode <rstrode@redhat.com>
Wed, 20 Jan 2016 17:22:29 +0000 (12:22 -0500)
committerRay Strode <rstrode@redhat.com>
Wed, 20 Jan 2016 19:29:15 +0000 (14:29 -0500)
create_shm_pool unlinks the temporary file a little,
too late. It should be unlinked before ftruncate()
is called for two reasons:

1) if ftruncate fails, the file is currently not
getting cleaned up at all
2) in theory, if the file is public some other process
could muck with it

This commit just moves the unlink call a little higher
up.

https://bugzilla.gnome.org/show_bug.cgi?id=760897

gdk/wayland/gdkdisplay-wayland.c

index 97eebcaae479a03082a9aa51e2610858c4cb238b..2f0c64e52149ae1c79f94ac8b2d91788118a85ef 100644 (file)
@@ -941,6 +941,7 @@ create_shm_pool (struct wl_shm  *shm,
                   filename, g_strerror (errno));
       return NULL;
     }
+  unlink (filename);
 
   stride = width * 4;
   size = stride * height;
@@ -953,7 +954,6 @@ create_shm_pool (struct wl_shm  *shm,
     }
 
   data = mmap (NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
-  unlink (filename);
 
   if (data == MAP_FAILED)
     {